﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Microsoft.Practices.Unity;
using ePlanet.SingleWell.Models;
using ePlanet.SingleWell.Services;
using Web.SystemConfig.SysCache;
using Web.SystemConfig.WorkFlow;
using DreamBuilder.Core.Container;
using ePlanet.SingleWell.Business;
using Web.SystemConfig.Models;
using Web.SystemConfig.Services;
using Web.SystemConfig.Business;
using Web.SystemLogin.Models;
using System.Data;
using ePlanet.ArchiveMange.Models;

using Wuqi.Webdiyer;

using DreamBuilder.Common;
using ePlanet.ArchiveMange.Services;
using ePlanet.ArchiveMange.Enum;
using Aspose.Cells;
using ePlanet.ArchiveMange.DataAccess;
using System.IO;
using ePlanet.Entities;
using CommonModule;
using System.Collections;

namespace Web.Views.DataManage
{
    public partial class ArchiveManage : PageBase
    {
        private ArchiveBaseType _baseArchiveType;

        protected ArchiveBaseType BaseArchiveType
        {
            get
            {
                if ((int)_baseArchiveType == 0)
                {
                    int o_int = 0;
                    if (Request.QueryString["archivetype"] != null)
                    {
                        int.TryParse(Request.QueryString["archivetype"], out o_int);
                    }

                    _baseArchiveType = (ArchiveBaseType)ArchiveMenuService.GetArchiveBaseIDById(o_int);
                }
                return _baseArchiveType;
            }
        }

        [Dependency]
        public IArchiveMenuService ArchiveMenuService
        {
            get;
            set;
        }

        [Dependency]
        public IAccountArchiveService AccountArchiveService
        {
            get;
            set;
        }

        [Dependency]
        public IOilSearchArchiveService OilSearchArchiveService
        {
            get;
            set;
        }
        
        [Dependency]
        public IAudioArchiveService AudioArchiveService
        {
            get;
            set;
        }

        [Dependency]
        public IBuildProjectArchiveService BuildProjectArchiveService
        {
            get;
            set;
        }

        [Dependency]
        public ICDArchiveService CDArchiveService
        {
            get;
            set;
        }

        [Dependency]
        public IDocumentArchiveService DocumentArchiveService
        {
            get;
            set;
        }
       
        [Dependency]
        public IEquipmentService EquipmentService
        {
            get;
            set;
        }

        [Dependency]
        public IRealKindArchiveService RealKindArchiveService
        {
            get;
            set;
        }

        [Dependency]
        public ITechArchiveService TechArchiveService
        {
            get;
            set;
        }

        [Dependency]
        public IPageFileService PageFileService
        {
            get;
            set;
        }

        [Dependency]
        public ICodeTable CodeTableService
        {
            get;
            set;
        }

        /// <summary>
        /// 文档类型ID
        /// </summary>
        public int ArchiveTypeID
        {
            get
            {
                int o_int = 0;
                if (Request.QueryString["archivetype"] != null)
                {
                    if (int.TryParse(Request.QueryString["archivetype"], out o_int))
                    {
                        return o_int;
                    }
                    else
                    {
                        throw new Exception("档案类型错误");
                    }
                }
                else
                {
                    throw new Exception("档案类型不能为空");
                }
            }
        }

        private string archiveTypeName = string.Empty;
        public string ArchiveTypeName
        {
            get 
            {
                if (!string.IsNullOrEmpty(archiveTypeName))
                {
                    return this.archiveTypeName;
                }
                string name = string.Empty;
                ArchiveMangeModal.ARCHIVEMENUDataTable dataTable = ArchiveMenuService.GetArchiveMenuById(this.ArchiveTypeID.ToString());
                if(dataTable != null)
                {
                    ArchiveMangeModal.ARCHIVEMENURow row = dataTable.Rows[0] as ArchiveMangeModal.ARCHIVEMENURow;
                    if (row != null)
                    {
                        name = row.ARCHIVEMENU;
                        archiveTypeName = row.ARCHIVEMENU;
                    }
                }
                return name;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //如果是文书类，则转向其他页面
                if (this.ArchiveTypeID == (int)ArchiveTableEnum.Document)
                {
                    this.Response.Redirect("DocumentArchiveFrame.aspx");
                }
                //如果是油气勘探--综合类，则转向其他页面
                else if (this.ArchiveTypeID == (int)ArchiveTableEnum.OliSearchK01)
                {
                    this.Response.Redirect("OilSearchZongheFrame.aspx");
                }
                //其他类别，当前页面展示
                else
                {
                    BindSingleWellData();
                }
            }
            this.sch.SearchEvent += new EventHandler(sch_SearchEvent);
           
        }

        void sch_SearchEvent(object sender, EventArgs e)
        {
            List<string> colNames = new List<string>();
            if (this.DataSourseScheme != null)
            {
                foreach (DataColumn col in this.DataSourseScheme.Columns)
                {
                    colNames.Add(col.ColumnName);
                }
            }
            this.Where = this.sch.WhereString;
            this.ViewState["SelectItemsInAllPages"] = null;
            this.gv_SingleWellList.ResetSelectItemsInViewState(null);
            this.IsExportRowsOrColumnsEmpty.Value = "false";
            this.aspNetPagerSearch.CurrentPageIndex = 1;
            BindSingleWellData();
        }

        public DataTable DataSourseScheme
        {
            get
            {
                return this.ViewState["DataSourseScheme"] as DataTable;
            }
            set
            {
                this.ViewState["DataSourseScheme"] = value;
            }
        }

        public string Where
        {
            get
            {
                if (this.ViewState["FilterWhere"] != null)
                {
                    //if (!this.CurrentUser.Org_FullFondsNum.ToLower().Equals("dqyt.218"))
                    //{
                    return " FullFondsNum = '" + this.CurrentUser.Org_FullFondsNum + "' and " + this.ViewState["FilterWhere"];
                    //}
                    //else
                    //{
                    //    return this.ViewState["FilterWhere"] as string;
                    //}
                }
                else
                {
                    //if (!this.CurrentUser.Org_FullFondsNum.ToLower().Equals("dqyt.218"))
                    //{
                    return " 1=1 and FullFondsNum = '" + this.CurrentUser.Org_FullFondsNum + "' ";
                    //}
                    //else
                    //{
                    //    return " 1=1 ";
                    //}
                }
            }
            set
            {
                this.ViewState["FilterWhere"] = value;
            }
        }

        private void BindSingleWellData()
        {
            int beginNum = this.aspNetPagerSearch.PageSize*(this.aspNetPagerSearch.CurrentPageIndex-1)+1;
            int pageSize = this.aspNetPagerSearch.PageSize;
            int recordCount = 0;
            DataTable oDataTable = null;

            //added by jiejiep 
            //添加状态限制-标识数据已审核完成
            int finishStatusID = new ArchiveCacheFacade().GetStatusRuleCache().GetFinishStatus(ArchiveTypeID);
            ArchiveCommon archiveCommon = new ArchiveCommon();
            oDataTable = archiveCommon.GetArchiveByPage(finishStatusID, string.Concat(ArchiveTypeID), beginNum, pageSize, out recordCount, Where);
            if (this.DataSourseScheme == null)
            {
                this.DataSourseScheme = oDataTable.Clone();
            }

            SetGridViewEnableField(oDataTable);
            if (!IsPostBack)
            {
                InitCheckBoxList(oDataTable);
            }
            ConvertCodeTableInfo.ReplaceKeyToValueInDataTable(oDataTable);

            if (oDataTable != null)
            {
                this.gv_SingleWellList.PageSize = pageSize;
                this.gv_SingleWellList.DataSource = oDataTable;
                this.gv_SingleWellList.DataBind();
                this.aspNetPagerSearch.RecordCount = recordCount;   
            }
        }

        private void SetGridViewEnableField(DataTable oDataTable)
        {
            if (oDataTable != null)
            {
                foreach (DataControlField dataControlField in this.gv_SingleWellList.Columns)
                {
                    if (dataControlField is BoundField)
                    {
                        BoundField boundField = dataControlField as BoundField;
                        if (boundField != null)
                        {
                            bool flag = false;
                            foreach (DataColumn col in oDataTable.Columns)
                            {
                                if (boundField.DataField.ToLower() == col.ColumnName.ToLower())
                                {
                                    flag = true;
                                    break;
                                }
                            }
                            if (!flag)
                            {
                                boundField.Visible = false;
                            }
                        }
                    }
                }
            }
        }

        protected void aspNetPagerSearch_PageChanging(object sender, PageChangingEventArgs e)
        {
            SetSelectItemsInAllPages();
            this.IsExportRowsOrColumnsEmpty.Value = "false";
            aspNetPagerSearch.CurrentPageIndex = e.NewPageIndex;
            BindSingleWellData();
        }

        protected void aspNetPagerSearch_PageSizeChanging(object sender, EventArgs args)
        {
            this.ViewState["SelectItemsInAllPages"] = null;
            this.gv_SingleWellList.ResetSelectItemsInViewState(null);
            this.IsExportRowsOrColumnsEmpty.Value = "false";
            BindSingleWellData();
        }

        /// <summary>
        /// 获取所有页选择的行
        /// </summary>
        public void SetSelectItemsInAllPages()
        {
            if (this.ViewState["SelectItemsInAllPages"] == null)
            {
                this.ViewState["SelectItemsInAllPages"] = new System.Collections.ArrayList();
            }
            System.Collections.ArrayList selectItemsInAllPages = this.ViewState["SelectItemsInAllPages"] as System.Collections.ArrayList;
            if (this.gv_SingleWellList.ShowCheckBox)
            {
                for (int i = 0; i < this.gv_SingleWellList.Rows.Count; i++)
                {
                    //主键ID[如果没有配置主键，会抛出异常]
                    string id = this.gv_SingleWellList.DataKeys[i].Value.ToString();
                    foreach (TableCell tc in this.gv_SingleWellList.Rows[i].Cells)
                    {
                        if (tc.Controls.Count > 0 && tc.Controls[0] is System.Web.UI.WebControls.CheckBox)
                        {
                            System.Web.UI.WebControls.CheckBox cb = tc.Controls[0] as System.Web.UI.WebControls.CheckBox;
                            if (cb.Checked)
                            {
                                if (!selectItemsInAllPages.Contains(id))
                                {
                                    selectItemsInAllPages.Add(id);
                                }
                            }
                            else
                            {
                                if (selectItemsInAllPages.Contains(id))
                                {
                                    selectItemsInAllPages.Remove(id);
                                }
                            }
                        }
                    }
                }
            }

            this.ViewState["SelectItemsInAllPages"] = selectItemsInAllPages;

            this.gv_SingleWellList.ResetSelectItemsInViewState(selectItemsInAllPages);
        }
        #region 原来导出事件
        //protected void ExportButton_Click(Object sender, EventArgs e)
        //{
        //    DataTable dtDataSource = this.DataSourseScheme;

        //    System.Collections.ArrayList dataIds = null;
        //    if (this.IsExportAllRowsHasSelected.SelectedValue == "0")
        //    {
        //        this.gv_SingleWellList.ResetSelectItemsInViewState(null);
        //        dataIds = this.gv_SingleWellList.SelectItems;
        //        SetSelectItemsInAllPages();
        //    }
        //    else
        //    {
        //        SetSelectItemsInAllPages();
        //        dataIds = this.ViewState["SelectItemsInAllPages"] as System.Collections.ArrayList;
        //    }

        //    List<ColumnNameToCHS> columnNameToCHSList = ColumnNameToCHS.GetColumnNameToCHSList();
        //    List<string> selectColumnNames = new List<string>();
        //    foreach(ListItem item in this.cblSelectCols.Items)
        //    {
        //        if (item.Selected == true && dtDataSource.Columns.Contains(item.Value))
        //        {
        //            selectColumnNames.Add(item.Value);
        //        }
        //    }

        //    if (dataIds.Count == 0  || (selectColumnNames.Count == 0))
        //    {
        //        this.IsExportRowsOrColumnsEmpty.Value = "ColumnsOrRowsEmpty";
        //        return;
        //    }
        //    else
        //    {
        //        List<string> ids = new List<string>();
        //        foreach(string dataId in dataIds)
        //        {
        //            ids.Add(dataId);
        //        }
        //        ArchiveCommon ArchiveCommonDAL = new ArchiveCommon();
        //        dtDataSource = ArchiveCommonDAL.GetArchiveByIds(ids, ArchiveTypeID);
        //        ConvertCodeTableInfo.ReplaceKeyToValueInDataTable(dtDataSource);
        //        this.IsExportRowsOrColumnsEmpty.Value = "false";
        //    }

        //    if (dtDataSource == null || dtDataSource.Rows.Count == 0)
        //    {
        //        this.IsExportRowsOrColumnsEmpty.Value = "DataSourceEmpty";
        //        return;
        //    }

        //    DataTable dtDataSourceCopy = dtDataSource.Copy();
        //    foreach (DataColumn col in dtDataSource.Columns)
        //    {
        //        if (col.ColumnName.ToLower() != "dataid" && !selectColumnNames.Contains(col.ColumnName,StringComparer.OrdinalIgnoreCase))
        //        {
        //            if (dtDataSourceCopy.Columns.CanRemove(dtDataSourceCopy.Columns[col.ColumnName]))
        //            {
        //                dtDataSourceCopy.Columns.Remove(col.ColumnName);
        //            }
        //        }
        //    }

        //    string wheres = string.Empty;
        //    if (dtDataSourceCopy.Columns.Contains("DataId") && dataIds.Count > 0)
        //    {
        //        wheres = " 1=1 AND DataId IN ( ";
        //        foreach (string dataId in dataIds)
        //        {
        //            wheres += "'" + dataId + "',";
        //        }
        //        wheres = wheres.Remove(wheres.Length - 1);
        //        wheres += " ) ";
        //    }
            
        //    DataRow[] rows = dtDataSourceCopy.Select(wheres);
        //    DataTable dtArchiveExportDataSource = dtDataSourceCopy.Clone();
        //    foreach (DataRow row in rows)
        //    {
        //        dtArchiveExportDataSource.Rows.Add(row.ItemArray);
        //    }
        //    if (dtArchiveExportDataSource.Columns.Contains("DataId"))
        //    {
        //        dtArchiveExportDataSource.Columns["DataId"].SetOrdinal(0);
        //    }

        //    string excelImportName =this.ArchiveTypeName.Replace(" ","")+"_"+string.Concat(Guid.NewGuid())+".xls";
        //    string userTempDirect = this.Request.PhysicalApplicationPath + "\\TempDatas\\" + UserSessionTempDirectoryId;
        //    if (!System.IO.Directory.Exists(userTempDirect))
        //    {
        //        System.IO.Directory.CreateDirectory(userTempDirect);
        //    }
        //    string excelImportTempPath = System.IO.Path.Combine(userTempDirect,excelImportName);
        //    Workbook workbook = new Workbook();
        //    workbook.Worksheets.Clear();
        //    workbook.Worksheets.Add(ArchiveTypeName+" (卷)");
        //    Cells cells = null;
           
        //    cells = workbook.Worksheets[0].Cells;
        //    int colIndex = 0;
        //    for (int i=0;i< dtArchiveExportDataSource.Columns.Count;i++)
        //    {
        //        DataColumn column = dtArchiveExportDataSource.Columns[i];
        //        string columnDisplayName = column.ColumnName;
        //        foreach (ColumnNameToCHS columnNameToCHS in columnNameToCHSList)
        //        {
        //            if (column.ColumnName.ToLower() == columnNameToCHS.ColumnName.ToLower())
        //            {
        //                columnDisplayName = columnNameToCHS.CHSName;
        //                break;
        //            }
        //        }
        //        if (i < 2)
        //        {
        //            cells[0, colIndex++].PutValue(columnDisplayName);
        //        }
        //        else
        //        {
        //            cells[0, ++colIndex].PutValue(columnDisplayName);
        //        }
        //    }
        //    cells[0,2].PutValue("电子文件");
        //    DataHelper dataHelper = new DataHelper();
        //    string dbHelperName = dataHelper.GetDbHelperNameByArchiveType(string.Concat(this.ArchiveTypeID));
        //    if (dtArchiveExportDataSource.Rows.Count > 0)
        //    {
        //        int rowIndex = 1;
        //        for (int i =0; i < dtArchiveExportDataSource.Rows.Count;i++)
        //        {
        //            for (int j = 0; j < dtArchiveExportDataSource.Columns.Count; j++)
        //            {
        //                if (j < 2)
        //                {
        //                    cells[rowIndex, j].PutValue(dtArchiveExportDataSource.Rows[i][j]);
        //                }
        //                else
        //                {
        //                    cells[rowIndex, j+1].PutValue(dtArchiveExportDataSource.Rows[i][j]);
        //                }
        //            }
        //            DataTable table = dataHelper.GetAttachmentIds(new List<string>() { string.Concat(dtArchiveExportDataSource.Rows[i]["DataId"]) }, dbHelperName);
        //            cells[rowIndex, 2].PutValue(table.Rows.Count);
        //            foreach (DataRow row in table.Rows)
        //            {
        //                AttachmentInfo info = new AttachmentInfo { Id = string.Concat(row["ATTACHMENTID"]), Name = string.Concat(row["ATTACHMENTNAME"]), FileSize = int.Parse(string.Concat(row["ATTACHMENTSIZE"])), SaveDirectory = string.Concat(dtArchiveExportDataSource.Rows[i]["ArchiveNum"]) };
        //                string infoJson = Newtonsoft.Json.JsonConvert.SerializeObject(info);
        //                cells[++rowIndex, 2].PutValue(infoJson);
        //            }
        //            rowIndex++;
        //        }
        //        //cells.ImportDataTable(dtArchiveExportDataSource, false, 1, 0, dtArchiveExportDataSource.Rows.Count, dtArchiveExportDataSource.Columns.Count, true, "{0: yyyy-MM-dd}", false);
        //    }
            
        //    List<string> archiveIds = new List<string>();
        //    foreach(string dataId in dataIds)
        //    {
        //        archiveIds.Add(dataId);
        //    }
        //    DataTable dtPageFileExportDataSource = PageFileService.GetPageFileByArchiveIdListAndType(archiveIds, ArchiveTypeID);
        //    if (dtPageFileExportDataSource != null && dtPageFileExportDataSource.Rows.Count>0)
        //    {
        //        workbook.Worksheets.Add(ArchiveTypeName + " (卷内件)");
        //        if (dtPageFileExportDataSource.Columns.Contains("F_archiveid"))
        //        {
        //            dtPageFileExportDataSource.Columns["F_archiveid"].SetOrdinal(0);
        //        }
                
        //        cells = workbook.Worksheets[1].Cells;
        //        colIndex = 0;
        //        DataTable dtPageFileExportDataSourceClone = dtPageFileExportDataSource.Clone();
        //        List<DataColumn> columnRemoves = new List<DataColumn>();
        //        for (int i = 0; i < dtPageFileExportDataSourceClone.Columns.Count; i++) 
        //        {
        //            DataColumn column = dtPageFileExportDataSourceClone.Columns[i];
        //            if (column.ColumnName.ToLower() == "createuserid" || column.ColumnName.ToLower() == "createtime" || column.ColumnName.ToLower() == "lastupdateuser" || column.ColumnName.ToLower() == "lastupdatetime")
        //            {
        //                if (dtPageFileExportDataSource.Columns.CanRemove(dtPageFileExportDataSource.Columns[column.ColumnName]))
        //                {
        //                    columnRemoves.Add(dtPageFileExportDataSource.Columns[column.ColumnName]);
        //                }
        //            }
        //        }
        //        foreach (DataColumn column in columnRemoves)
        //        {
        //            dtPageFileExportDataSource.Columns.Remove(column);
        //        }
        //        for (int i = 0; i <  dtPageFileExportDataSourceClone.Columns.Count; i++)
        //        {
        //            DataColumn column = dtPageFileExportDataSourceClone.Columns[i];
        //            string columnDisplayName = column.ColumnName;
        //            foreach (ColumnNameToCHS columnNameToCHS in columnNameToCHSList)
        //            {
        //                if (column.ColumnName.ToLower() == columnNameToCHS.ColumnName.ToLower())
        //                {
        //                    if (column.ColumnName.ToLower() == "pagenum")
        //                    {
        //                        columnDisplayName = "页号";
        //                    }
        //                    else
        //                    {
        //                        columnDisplayName = columnNameToCHS.CHSName;
        //                    }
        //                    break;
        //                }
        //            }
        //            if (i < 2)
        //            {
        //                cells[0, colIndex++].PutValue(columnDisplayName);
        //            }
        //            else
        //            {
        //                cells[0, ++colIndex].PutValue(columnDisplayName);
        //            }
        //        }
        //        cells[0, 2].PutValue("电子文件");
        //        if (dtPageFileExportDataSource.Rows.Count > 0)
        //        {
        //            ConvertCodeTableInfo.ReplaceKeyToValueInDataTable(dtPageFileExportDataSource);
        //            int rowIndex = 1;
        //            for (int i = 0; i < dtPageFileExportDataSource.Rows.Count; i++)
        //            {
        //                for (int j = 0; j < 2; j++)
        //                {
        //                    cells[rowIndex, j].PutValue(dtPageFileExportDataSource.Rows[i][j]);
        //                }
        //                for (int j = 3; j < dtPageFileExportDataSource.Columns.Count; j++)
        //                {
        //                    cells[rowIndex, j].PutValue(dtPageFileExportDataSource.Rows[i][j - 1]);
        //                }
        //                DataTable table = dataHelper.GetAttachmentIds(new List<string>() { string.Concat(dtPageFileExportDataSource.Rows[i]["DataId"]) }, AttachDbHelperString.PageFile);
        //                cells[rowIndex, 2].PutValue(table.Rows.Count);
        //                string archiveNum = string.Empty;
        //                DataRow[] tempRow = dtArchiveExportDataSource.Select(string.Format("DataId = '{0}'", string.Concat(dtPageFileExportDataSource.Rows[i]["F_ArchiveId"])));
        //                if (tempRow.Length > 0)
        //                {
        //                    archiveNum = string.Concat(tempRow[0]["ArchiveNum"]);
        //                }
        //                foreach (DataRow row in table.Rows)
        //                {
        //                    AttachmentInfo info = new AttachmentInfo { Id = string.Concat(row["ATTACHMENTID"]), Name = string.Concat(row["ATTACHMENTNAME"]), FileSize = int.Parse(string.Concat(row["ATTACHMENTSIZE"])), SaveDirectory = archiveNum };
        //                    string infoJson = Newtonsoft.Json.JsonConvert.SerializeObject(info);
        //                    cells[++rowIndex, 2].PutValue(infoJson);
        //                }
        //                rowIndex++;
        //            }
        //            //cells.ImportDataTable(dtPageFileExportDataSource, false, 1, 0, dtPageFileExportDataSource.Rows.Count, dtPageFileExportDataSource.Columns.Count, true, "{0: yyyy-MM-dd}", false);
        //        }
        //    }
        //    workbook.Save(excelImportTempPath);
        //    //this.Response.Redirect("~/TempDatas/" + UserSessionTempDirectoryId + "/" + excelImportName, false);//+ this.CurrentUser.User_ID +"/"
        //    string webAddress = "http://" + this.Request.Url.Authority + this.Request.ApplicationPath;
        //    webAddress = HttpUtility.UrlEncode(webAddress);
        //    string url = "/FilesUploadClickOnce/FilesUpload.application?UserId=" + this.CurrentUser.User_ID + "&WebAddress=" + webAddress + "&CatalogId=" + this.ArchiveTypeID + "&Type=Archive" + "&ExcelImportTempPath=" + Uri.EscapeUriString(excelImportTempPath) + "&ApplicationType=ArchiveExport";
        //    this.Response.Redirect(this.Request.ApplicationPath + url, false);
        //}
        #endregion

        /// <summary>
        /// 导出按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ExportButton_Click(object sender, EventArgs e)
        {
            DataTable dtDataSource = this.DataSourseScheme;

            System.Collections.ArrayList dataIds = null;
            if (this.IsExportAllRowsHasSelected.SelectedValue == "0")
            {
                this.gv_SingleWellList.ResetSelectItemsInViewState(null);
                dataIds = this.gv_SingleWellList.SelectItems;
                SetSelectItemsInAllPages();
            }
            else
            {
                SetSelectItemsInAllPages();
                dataIds = this.ViewState["SelectItemsInAllPages"] as System.Collections.ArrayList;
            }

            List<ColumnNameToCHS> columnNameToCHSList = ColumnNameToCHS.GetColumnNameToCHSList();
            List<string> selectColumnNames = new List<string>();
            foreach (ListItem item in this.cblSelectCols.Items)
            {
                if (item.Selected == true && dtDataSource.Columns.Contains(item.Value))
                {
                    selectColumnNames.Add(item.Value);
                }
            }

            if (dataIds.Count == 0 || (selectColumnNames.Count == 0))
            {
                this.IsExportRowsOrColumnsEmpty.Value = "ColumnsOrRowsEmpty";
                return;
            }
            else
            {
                List<string> ids = new List<string>();
                foreach (string dataId in dataIds)
                {
                    ids.Add(dataId);
                }
                ArchiveCommon ArchiveCommonDAL = new ArchiveCommon();
                dtDataSource = ArchiveCommonDAL.GetArchiveByIds(ids, ArchiveTypeID);
                ConvertCodeTableInfo.ReplaceKeyToValueInDataTable(dtDataSource);
                this.IsExportRowsOrColumnsEmpty.Value = "false";
            }

            if (dtDataSource == null || dtDataSource.Rows.Count == 0)
            {
                this.IsExportRowsOrColumnsEmpty.Value = "DataSourceEmpty";
                return;
            }

            DataTable dtDataSourceCopy = dtDataSource.Copy();
            foreach (DataColumn col in dtDataSource.Columns)
            {
                if (col.ColumnName.ToLower() != "dataid" && !selectColumnNames.Contains(col.ColumnName, StringComparer.OrdinalIgnoreCase))
                {
                    if (dtDataSourceCopy.Columns.CanRemove(dtDataSourceCopy.Columns[col.ColumnName]))
                    {
                        dtDataSourceCopy.Columns.Remove(col.ColumnName);
                    }
                }
            }

            string wheres = string.Empty;
            if (dtDataSourceCopy.Columns.Contains("DataId") && dataIds.Count > 0)
            {
                wheres = " 1=1 AND DataId IN ( ";
                foreach (string dataId in dataIds)
                {
                    wheres += "'" + dataId + "',";
                }
                wheres = wheres.Remove(wheres.Length - 1);
                wheres += " ) ";
            }

            DataRow[] rows = dtDataSourceCopy.Select(wheres);
            DataTable dtArchiveExportDataSource = dtDataSourceCopy.Clone();
            foreach (DataRow row in rows)
            {
                dtArchiveExportDataSource.Rows.Add(row.ItemArray);
            }
            if (dtArchiveExportDataSource.Columns.Contains("DataId"))
            {
                dtArchiveExportDataSource.Columns["DataId"].SetOrdinal(0);
            }
            dbDataTableAddXuHao(dtArchiveExportDataSource, "Xuhao");
            DataSet ds = new DataSet();
            //电子文件
            dtArchiveExportDataSource.Columns.Add("AttachmentCount");//存储电子文件数目
            dtArchiveExportDataSource.Columns.Add("AttachmentPath");//电子文件路径
            DataHelper dataHelper = new DataHelper();
            string dbHelperName = dataHelper.GetDbHelperNameByArchiveType(string.Concat(this.ArchiveTypeID));
            DataTable dtArchiveExportDataSourceCopy = dtArchiveExportDataSource.Clone();
            for (int i = 0; i < dtArchiveExportDataSource.Rows.Count; i++)
            {
                DataRow rowExport = dtArchiveExportDataSource.Rows[i];
                DataTable table = dataHelper.GetAttachmentIds(new List<string>() { rowExport["DataId"].ToString() }, dbHelperName);
                rowExport["AttachmentCount"] = table.Rows.Count;
                if (table.Rows.Count > 0)
                {
                    for (int j = 0; j < table.Rows.Count; j++)
                    {
                        DataRow rowAttach = table.Rows[j];
                        AttachmentInfo info = new AttachmentInfo { Id = string.Concat(rowAttach["ATTACHMENTID"]), Name = string.Concat(rowAttach["ATTACHMENTNAME"]), FileSize = int.Parse(string.Concat(rowAttach["ATTACHMENTSIZE"])), SaveDirectory = string.Concat(rowExport["ArchiveNum"]), DbHelperString = dbHelperName };
                        string infoJson = Newtonsoft.Json.JsonConvert.SerializeObject(info);
                        if (j == 0)
                        {
                            rowExport["AttachmentPath"] = infoJson;
                            dtArchiveExportDataSourceCopy.ImportRow(rowExport);
                        }
                        else
                        {
                            DataRow rowExportNewRow = dtArchiveExportDataSourceCopy.NewRow();
                            rowExportNewRow["AttachmentPath"] = infoJson;
                            dtArchiveExportDataSourceCopy.Rows.Add(rowExportNewRow);
                        }
                    }
                }
                else
                {
                    dtArchiveExportDataSourceCopy.ImportRow(rowExport);
                }
            }
            //卷信息存入dataset
            ds.Tables.Add(dtArchiveExportDataSourceCopy);
            //卷内件
            List<string> archiveIds = new List<string>();
            foreach(string dataId in dataIds)
            {
                archiveIds.Add(dataId);
            }
            DataTable dtPageFileExportDataSource = PageFileService.GetPageFileByArchiveIdListAndType(archiveIds, ArchiveTypeID);
            ConvertCodeTableInfo.ReplaceKeyToValueInDataTable(dtPageFileExportDataSource);
            dtPageFileExportDataSource.Columns.Add("AttachmentCount");//存储电子文件数目
            dtPageFileExportDataSource.Columns.Add("AttachmentPath");//电子文件路径
            DataTable dtPageFileExportDataSourceCopy = dtPageFileExportDataSource.Clone();
            //卷内件电子文件
            if (dtPageFileExportDataSource.Rows.Count > 0)
            {
                for (int i = 0; i < dtPageFileExportDataSource.Rows.Count; i++)
                {
                    DataRow rowExport = dtPageFileExportDataSource.Rows[i];
                    string archiveNum = string.Empty;
                    DataRow[] tempRow = dtArchiveExportDataSource.Select(string.Format("DataId = '{0}'", string.Concat(rowExport["F_ArchiveId"])));
                    if (tempRow.Length > 0)
                    {
                        archiveNum = string.Concat(tempRow[0]["ArchiveNum"]);
                    }
                    DataTable table = dataHelper.GetAttachmentIds(new List<string>() { string.Concat(dtPageFileExportDataSource.Rows[i]["DataId"]) }, AttachDbHelperString.PageFile);
                    rowExport["AttachmentCount"] = table.Rows.Count;
                    if (table.Rows.Count > 0)
                    {
                        for (int j = 0; j < table.Rows.Count; j++)
                        {
                            DataRow rowAttach = table.Rows[j];
                            AttachmentInfo info = new AttachmentInfo { Id = string.Concat(rowAttach["ATTACHMENTID"]), Name = string.Concat(rowAttach["ATTACHMENTNAME"]), FileSize = int.Parse(string.Concat(rowAttach["ATTACHMENTSIZE"])), SaveDirectory = archiveNum,DbHelperString = AttachDbHelperString.PageFile };
                            string infoJson = Newtonsoft.Json.JsonConvert.SerializeObject(info);
                            if (j == 0)
                            {
                                rowExport["AttachmentPath"] = infoJson;
                                dtPageFileExportDataSourceCopy.ImportRow(rowExport);
                            }
                            else
                            {
                                DataRow rowExportNewRow = dtPageFileExportDataSourceCopy.NewRow();
                                rowExportNewRow["AttachmentPath"] = infoJson;
                                dtPageFileExportDataSourceCopy.Rows.Add(rowExportNewRow);
                            }
                        }
                    }
                    else
                    {
                        dtPageFileExportDataSourceCopy.ImportRow(rowExport);
                    }
                }
            }
            DataTable dtPageFileExport = dtPageFileExportDataSourceCopy.Copy();
            dtPageFileExport.TableName = "Table1";
            //卷内件信息存入dataset
            ds.Tables.Add(dtPageFileExport);

            //保存到临时文件
            string templetePath = this.Server.MapPath(AsposeExprtToExcel.GetTempletePath(ArchiveTypeID));
            string excelImportName = this.ArchiveTypeName.Replace(" ", "") + "_" + string.Concat(Guid.NewGuid()) + ".xls";
            string userTempDirect = this.Request.PhysicalApplicationPath + "\\TempDatas\\" + UserSessionTempDirectoryId;
            if (!System.IO.Directory.Exists(userTempDirect))
            {
                System.IO.Directory.CreateDirectory(userTempDirect);
            }
            string excelImportTempPath = System.IO.Path.Combine(userTempDirect, excelImportName);
            //注释的代码做手动测试用，导出excel之后手动执行批量导出工具
            //AsposeExprtToExcel.ExportToExcel(ds, templetePath, ArchiveTypeName, this.Response);
            AsposeExprtToExcel.ExportToExcel(ds, templetePath, excelImportTempPath);
            string webAddress = "http://" + this.Request.Url.Authority + this.Request.ApplicationPath;
            webAddress = HttpUtility.UrlEncode(webAddress);
            string url = "/FilesUploadClickOnce/FilesUpload.application?UserId=" + this.CurrentUser.User_ID + "&WebAddress=" + webAddress + "&CatalogId=" + this.ArchiveTypeID + "&Type=Archive" + "&ExcelImportTempPath=" + Uri.EscapeUriString(excelImportTempPath) + "&ApplicationType=ArchiveExport";
            this.Response.Redirect(this.Request.ApplicationPath + url, false);
        }

        protected void bnPrintJuanCatagory_Click(object sender, EventArgs e)
        {
            System.Collections.ArrayList keys = new System.Collections.ArrayList();
            keys = this.gv_SingleWellList.SelectItems;
            if (keys.Count == 0)
            {
                Alert("未选中任何数据！");
                return;
            }
            Session["sjgl_jnml_selectedkeys"] = keys;
            this.Response.Redirect(string.Format("../ArchiveFlowView/PrintJuanCatagoryView.aspx?from=sjgl&archiveType={0}", ArchiveTypeID));
        }

        protected void bnPrintBoxCatagory_Click(object sender, EventArgs e)
        {
            ArrayList keys = new ArrayList();
            keys = this.gv_SingleWellList.SelectItems;
            if (keys.Count == 0)
            {
                //Alert("未选中任何数据！");
                //return;

                this.RegisterClientScriptBlock("alert",
                string.Format("<script>window.open('ArchiveCodeRangePrintView.aspx?from=sjgl&archiveType={0}', '_blank', 'width=600,height=300,resizable=no');</script>"
                , (int)ArchiveTypeID));
            }
            else
            {
                Session["sjgl_hnml_selectedkeys"] = keys;
                this.Response.Redirect(
                    string.Format("PrintBoxCatagoryView.aspx?from=sjgl&archiveType={0}", (int)ArchiveTypeID));
            }
            
        }

        protected void btnPrintBeikaoTable_Click(object sender, EventArgs e)
        {
            ArrayList keys = new ArrayList();
            keys = this.gv_SingleWellList.SelectItems;
            if (keys.Count == 0)
            {
                Alert("未选中任何数据！");
                return;
            }

            Session["sjgl_bkb_selectedkeys"] = keys;
            Response.Redirect("../ArchiveFlowView/PrintBeikaoTableView.aspx?from=sjgl&archiveType=" + ArchiveTypeID);
        }

        private void InitCheckBoxList(DataTable oDataTable)
        {
            if (oDataTable != null)
            {
                List<ColumnNameToCHS> columnNameToCHSList = ColumnNameToCHS.GetColumnNameToCHSList();
                DataTable dt = new DataTable();
                dt.Columns.Add("ColName", typeof(string));
                dt.Columns.Add("CHSName", typeof(string));
                DataRow row = null;
                foreach (DataColumn col in oDataTable.Columns)
                {
                    foreach (ColumnNameToCHS item in columnNameToCHSList)
                    {
                        if (col.ColumnName.ToLower() == item.ColumnName.ToLower())
                        {
                            row = dt.NewRow();
                            row["ColName"] = item.ColumnName;
                            row["CHSName"] = item.CHSName;
                            dt.Rows.Add(row);
                            break;
                        }
                    }
                }
                this.cblSelectCols.DataTextField = "CHSName";
                this.cblSelectCols.DataValueField = "ColName";
                this.cblSelectCols.DataSource = dt;
                this.cblSelectCols.DataBind();
                foreach (System.Web.UI.WebControls.ListItem ck in this.cblSelectCols.Items)
                { 
                    ck.Selected = true;
                }
            }
        }

        
        protected void gv_SingleWellList_OnDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e != null && e.Row != null && e.Row.RowType == DataControlRowType.DataRow)
            {
                string id = this.gv_SingleWellList.DataKeys[e.Row.RowIndex].Value.ToString();
                string elecFileCount = ArchiveBusiHelper.Instance.GetTechnologyFileCount((int)BaseArchiveType, id);
                if (!string.IsNullOrEmpty(elecFileCount))
                {
                    e.Row.Cells[1].Text = string.Format("<img src='{0}' alt='{1}个电子文件' />",
                        "../../Images/qbz.jpg", elecFileCount);
                }
                else
                {
                    e.Row.Cells[1].Text = string.Empty;
                }
            }
            return;
            try
            {
                if (e != null && e.Row != null && e.Row.RowType == DataControlRowType.DataRow)
                {
                    string id = this.gv_SingleWellList.DataKeys[e.Row.RowIndex].Value.ToString();
                    bool flag = false;
                    if(this.ViewState["SelectItemsInAllPages"] != null)
                    {
                        foreach (string dataId in this.ViewState["SelectItemsInAllPages"] as System.Collections.ArrayList)
                        {
                            if (dataId == id)
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (flag)
                        {
                            foreach (TableCell tc in e.Row.Cells)
                            {
                                if (tc.Controls.Count > 0 && tc.Controls[0] is System.Web.UI.WebControls.CheckBox)
                                {
                                    System.Web.UI.WebControls.CheckBox cb = tc.Controls[0] as System.Web.UI.WebControls.CheckBox;
                                    if (cb.Checked != flag)
                                    {
                                        cb.Checked = flag;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            { 
                
            }
        }

        

        protected void Deleted_Click(Object sender, EventArgs e)
        {
            try
            {
                LinkButton linkButton = sender as LinkButton;
                if (linkButton != null)
                {
                    string archiveId = linkButton.CommandArgument;
                    if (!string.IsNullOrEmpty(archiveId))
                    {
                        ArchiveCommon archiveCommon = new ArchiveCommon();
                        try
                        {
                            archiveCommon.DeleteArchive(archiveId, ArchiveTypeID);
                        }
                        catch (Exception ex)
                        {
                            this.Alert("删除失败：" + ex.Message);
                            return;
                        }
                        DataTable oDataTable1 = this.gv_SingleWellList.DataSource as DataTable;
                        if (oDataTable1 != null)
                        {
                            DataTable oDataTable2 = oDataTable1.Copy();
                            if (oDataTable2.Columns.Contains("DataId"))
                            {
                                foreach (DataRow row in oDataTable2.Rows)
                                {
                                    if (row["DataId"].ToString() == archiveId)
                                    {
                                        oDataTable2.Rows.Remove(row);
                                        this.gv_SingleWellList.DataSource = oDataTable2;
                                        this.gv_SingleWellList.DataBind();
                                        break;
                                    }
                                }
                            }
                        }
                        this.Alert("删除成功！");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        protected void gv_SingleWellList_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }

        protected void gv_SingleWellList_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {

        }

        private string UserSessionTempDirectoryId
        {
            get
            {
                return this.Session.SessionID;
            }
        }

        protected void AddFiles_Click(Object sender, EventArgs e)
        {
            DataTable dtDataSource = this.DataSourseScheme;
            System.Collections.ArrayList dataIds = null;
            if (this.IsExportAllRowsHasSelected.SelectedValue == "0")
            {
                this.gv_SingleWellList.ResetSelectItemsInViewState(null);
                dataIds = this.gv_SingleWellList.SelectItems;
                SetSelectItemsInAllPages();
            }
            else
            {
                SetSelectItemsInAllPages();
                dataIds = this.ViewState["SelectItemsInAllPages"] as System.Collections.ArrayList;
            }
            if (dataIds.Count == 0)
            {
                this.IsExportRowsOrColumnsEmpty.Value = "ColumnsOrRowsEmpty";
                return;
            }
            else
            {

                List<string> ids = new List<string>();
                foreach (string dataId in dataIds)
                {
                    ids.Add(dataId);
                }
                ArchiveCommon ArchiveCommonDAL = new ArchiveCommon();
                dtDataSource = ArchiveCommonDAL.GetArchiveByIds(ids, ArchiveTypeID);
                this.IsExportRowsOrColumnsEmpty.Value = "false";
            }
            if (dtDataSource == null || dtDataSource.Rows.Count == 0)
            {
                this.IsExportRowsOrColumnsEmpty.Value = "DataSourceEmpty";
                return;
            }
            DataTable dtDataSourceCopy = dtDataSource.Copy();
            string wheres = string.Empty;
            if (dtDataSourceCopy.Columns.Contains("DataId") && dataIds.Count > 0)
            {
                wheres = " 1=1 AND DataId IN ( ";
                foreach (string dataId in dataIds)
                {
                    wheres += "'" + dataId + "',";
                }
                wheres = wheres.Remove(wheres.Length - 1);
                wheres += " ) ";
            }
            DataRow[] rows = dtDataSourceCopy.Select(wheres);
            List<EntityIdAndTypeRelateAttachFilePath> entities = new List<EntityIdAndTypeRelateAttachFilePath>();
            foreach (DataRow row in rows)
            {
                EntityIdAndTypeRelateAttachFilePath item = new EntityIdAndTypeRelateAttachFilePath();
                item.EntityId = string.Concat(row["DataId"]);
                item.ArchiveNum = string.Concat(row["ArchiveNum"]);
                entities.Add(item);
            }
            string jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(entities);
            string webAddress = "http://" + this.Request.Url.Authority + this.Request.ApplicationPath;
            webAddress = HttpUtility.UrlEncode(webAddress);
            string url = "/FilesUploadClickOnce/FilesUpload.application?UserId=" + this.CurrentUser.User_ID + "&WebAddress=" + webAddress + "&CatalogId=" + this.ArchiveTypeID + "&Type=Archive" + "&DataIds=" + Uri.EscapeUriString(jsonStr);
            this.Response.Redirect(this.Request.ApplicationPath + url, false);
        }
    }

    public class ColumnNameToCHS
    {
        public string ColumnName { get; set; }
        public string CHSName { get; set; }
        public ColumnNameToCHS(string columnName, string chsName)
        {
            this.ColumnName = columnName;
            this.CHSName = chsName;
        }

        public static List<ColumnNameToCHS> GetColumnNameToCHSList()
        {
            //if (App Application["ColumnNameToCHSList"] != null && Application["ColumnNameToCHSList"] is List<ColumnNameToCHS>)
            //{
            //    return Application["ColumnNameToCHSList"] as List<ColumnNameToCHS>;
            //}

            List<ColumnNameToCHS> columnNameToCHSList = new List<ColumnNameToCHS>();
            columnNameToCHSList.Add(new ColumnNameToCHS("Title", "题名"));
            columnNameToCHSList.Add(new ColumnNameToCHS("ArchiveNum", "档号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("TempOrderNum", "临时序号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("ArchiveSource", "来源"));
            columnNameToCHSList.Add(new ColumnNameToCHS("FullFondsNum", "全宗号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("F_KeepTime", "保管期限"));
            columnNameToCHSList.Add(new ColumnNameToCHS("F_CarrierType", "载体类型"));
            columnNameToCHSList.Add(new ColumnNameToCHS("F_SecurityType", "密级"));
            columnNameToCHSList.Add(new ColumnNameToCHS("F_KeepSecurityTime", "保密期限"));
            columnNameToCHSList.Add(new ColumnNameToCHS("PageNum", "页数"));
            //add by guoyin
            //columnNameToCHSList.Add(new ColumnNameToCHS("PageCou", "页数"));
            //columnNameToCHSList.Add(new ColumnNameToCHS("Copies", "页数"));
            //columnNameToCHSList.Add(new ColumnNameToCHS("RecordUser", "著录人"));
            //columnNameToCHSList.Add(new ColumnNameToCHS("RecordTime", "文件日期"));
            //columnNameToCHSList.Add(new ColumnNameToCHS("Tiyao", "提要"));
            //end
            columnNameToCHSList.Add(new ColumnNameToCHS("FileNum", "文档编号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("PageFileNum", "件数"));
            columnNameToCHSList.Add(new ColumnNameToCHS("BoxNum", "盒号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("DocumentNum", "文件编号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("TypeNum", "型号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("OrderNum", "序号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("Publisher", "发布人"));
            columnNameToCHSList.Add(new ColumnNameToCHS("PublishOrgId", "立卷单位"));
            columnNameToCHSList.Add(new ColumnNameToCHS("PublishTime", "文件日期"));
            columnNameToCHSList.Add(new ColumnNameToCHS("FileOrgId", "归档单位"));
            columnNameToCHSList.Add(new ColumnNameToCHS("FileTime", "归档日期"));
            columnNameToCHSList.Add(new ColumnNameToCHS("F_Year", "年度"));
            columnNameToCHSList.Add(new ColumnNameToCHS("K_Year", "年度"));

            columnNameToCHSList.Add(new ColumnNameToCHS("StartAccount", "起凭证号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("EndAccount", "止凭证号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("AccountType", "凭证类别"));
            columnNameToCHSList.Add(new ColumnNameToCHS("AchiveLevel", "获奖级别"));
            columnNameToCHSList.Add(new ColumnNameToCHS("MainBodyNum", "正本数量"));
            columnNameToCHSList.Add(new ColumnNameToCHS("DoplicateBodyNum", "副本数量"));
            columnNameToCHSList.Add(new ColumnNameToCHS("WellNumber", "井号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("WellAddress", "地区名"));
            columnNameToCHSList.Add(new ColumnNameToCHS("WellType", "井别"));
            columnNameToCHSList.Add(new ColumnNameToCHS("StartTime", "起日期"));
            columnNameToCHSList.Add(new ColumnNameToCHS("EndTime", "止日期"));
            columnNameToCHSList.Add(new ColumnNameToCHS("Summary", "提要"));
            columnNameToCHSList.Add(new ColumnNameToCHS("Remark", "备注"));
            columnNameToCHSList.Add(new ColumnNameToCHS("StorageType", "存放位置"));
            columnNameToCHSList.Add(new ColumnNameToCHS("ExpansionInfo", "扩展信息"));
            columnNameToCHSList.Add(new ColumnNameToCHS("HuJianHao", "互见号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("GloryType", "获奖级别"));
            columnNameToCHSList.Add(new ColumnNameToCHS("ArchiveType", "档案类型"));
            columnNameToCHSList.Add(new ColumnNameToCHS("F_CATAGORYTYPE", "类别"));

            //Application["ColumnNameToCHSList"] = columnNameToCHSList;
            return columnNameToCHSList;
        }

        /// <summary>
        /// 历史档案的对照表
        /// </summary>
        /// <returns></returns>
        public static List<ColumnNameToCHS> GetColumnNameToCHSLisToHistoryArhive()
        {
            List<ColumnNameToCHS> columnNameToCHSList = new List<ColumnNameToCHS>();
            columnNameToCHSList.Add(new ColumnNameToCHS("Title", "题名"));
            columnNameToCHSList.Add(new ColumnNameToCHS("ArchiveNum", "档号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("ArchiveType", "类别号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("FullFondsNum", "全宗号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("F_KeepTime", "保管期限"));
            columnNameToCHSList.Add(new ColumnNameToCHS("F_CarrierType", "载体类型"));
            columnNameToCHSList.Add(new ColumnNameToCHS("F_SecurityType", "密级"));
            //columnNameToCHSList.Add(new ColumnNameToCHS("F_KeepSecurityTime", "保密期限"));         
            columnNameToCHSList.Add(new ColumnNameToCHS("PEGECOU", "页数"));
            columnNameToCHSList.Add(new ColumnNameToCHS("Copies", "份数"));
            columnNameToCHSList.Add(new ColumnNameToCHS("RecordUser", "著录人"));
            columnNameToCHSList.Add(new ColumnNameToCHS("ResponsibleUser", "责任者"));
            columnNameToCHSList.Add(new ColumnNameToCHS("FileUser", "归档人"));
             columnNameToCHSList.Add(new ColumnNameToCHS("FileOrgId", "归档单位"));
            columnNameToCHSList.Add(new ColumnNameToCHS("RecordTime", "文件日期"));
             columnNameToCHSList.Add(new ColumnNameToCHS("StartTime", "起日期"));
             columnNameToCHSList.Add(new ColumnNameToCHS("EndTime", "止日期"));
             columnNameToCHSList.Add(new ColumnNameToCHS("FileTime", "归档日期"));
             columnNameToCHSList.Add(new ColumnNameToCHS("DocumentNum", "文件编号"));
            columnNameToCHSList.Add(new ColumnNameToCHS("Tiyao", "提要"));
             columnNameToCHSList.Add(new ColumnNameToCHS("Summary", "主题词"));
             columnNameToCHSList.Add(new ColumnNameToCHS("Remark", "备注"));
            columnNameToCHSList.Add(new ColumnNameToCHS("AwardType", "获奖级别"));
            return columnNameToCHSList;
        }
    }

    /// <summary>
    /// 转换码表信息
    /// </summary>
    public class ConvertCodeTableInfo
    {
        /// <summary>
        /// 转换码表字段为码表展示信息
        /// </summary>
        /// <param name="oDataTable"></param>
        public static void ReplaceKeyToValueInDataTable(DataTable oDataTable)
        {
            if (oDataTable != null && oDataTable.Rows.Count>0)
            {
                ReplaceCodeTableKeyToValueInDataTableInner(oDataTable, "SecurityType", "F_SecurityType");
                ReplaceCodeTableKeyToValueInDataTableInner(oDataTable, "KeepSecurityTime", "F_KeepSecurityTime");
                ReplaceCodeTableKeyToValueInDataTableInner(oDataTable, "KeepTime", "F_KeepTime");
                ReplaceCodeTableKeyToValueInDataTableInner(oDataTable, "CarrierType", "F_CarrierType");
                ReplaceCodeTableKeyToValueInDataTableInner(oDataTable, "AccountType", "AccountType");
            }
        }

        private static void ReplaceCodeTableKeyToValueInDataTableInner(DataTable oDataTable,string Code_Type,string columnName)
        {
            ICodeTable CodeTableService = UContainer.Resolve<ICodeTable>();
            DataSet ds = CodeTableService.GetCodeTableDataByType(Code_Type);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                if (oDataTable.Columns.Contains(columnName))
                {
                    foreach (DataRow row in oDataTable.Rows)
                    {
                        bool flag = false;
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            if (string.Concat(row[columnName]).ToLower() == string.Concat(dr["CodeTableID"]).ToLower())
                            {
                                row[columnName] = dr["Code_Desc"];
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            row[columnName] = "";
                        }
                    }
                }
            }
        }

    }
}
